package de.thm.exa.holders;

import java.util.HashMap;

import de.thm.exa.helpers.Debugger;

public class PageMap extends HashMap<Long, PageList>
{
    private long INSERTS = 0;
    private long COLLISIONS = 0;
    
    public PageList put(Keyword keyword, Long key, Page value)
    {
        if(Debugger.COUNT_INSERTS) { INSERTS++; }
        
        PageList list;
        if( this.containsKey(key) )
        {
            list = this.get(key);
            list.add(value);
        } else {
            list = new PageList( keyword );
            list.add(value);
            this.put(key, list);
        }
        
        return list;
    }
    
    public void put(Keyword keyword, long key, PageList list)
    {
        for(Page page : list)
        {
            put(keyword, key, page);
        }
    }
    
    @Override
    public PageList get(Object key)
    {
        return super.get(key);
    }
    
    
    public void collided() { COLLISIONS++; }
    
    public long getInserts() { return INSERTS; }
    public long getCollisions() { return COLLISIONS; }
}
